<template>
    <div class="medicineList">
        <el-table  :data="tableData" style="width: 100%; margin-bottom: 20px;"
        row-key="id"
        border
        default-expand-all
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column prop="date" label="日期" sortable width="180">
        </el-table-column>
        <el-table-column prop="name" label="姓名"  width="180">
        </el-table-column>
        <el-table-column prop="address" label="地址">
        </el-table-column>
        <el-table-column prop="sort" label="排序" sortable width="180">
        </el-table-column>
        <el-table-column label="操作" align="center" width="380" fixed="right">
            <template slot-scope="scope">
                <el-button type="info" size="mini">上移</el-button>
                <el-button type="info" size="mini">下移</el-button>
                <el-button type="primary" size="mini" @click="goChange(scope.row.id)">修改</el-button>
                <el-button type="danger" size="mini"
                    @click="deleteMed(scope.row.id)">
                    删除
                </el-button>
                <el-button type="success" size="mini" v-if="scope.row.type=='fa'">
                    新增
                </el-button>
            </template>
        </el-table-column>
        </el-table>


        <!-- 分页器 -->
        <Pagination @getPagination="getPagination"></Pagination>
</div>
</template>

<script>


import Pagination from '@/components/Pagination'
export default {
    name: '',
    data() {
        return {
            listTotal: [],
            tableData:
                [{
                    id: 1,
                    date: '2016-05-02',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄',
                    sort:'1',
                    type:'fa'
                }, {
                    id: 2,
                    date: '2016-05-04',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1517 弄',
                    sort:'2',
                    type:'fa',
                    children: [{
                        id: 21,
                        date: '2016-05-01',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1519 弄'
                    }, {
                        id: 22,
                        date: '2016-05-01',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1519 弄'
                    }]
                }, {
                    id: 3,
                    date: '2016-05-01',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1519 弄',
                    sort:'3',
                    type:'fa',
                    children: [{
                        id: 31,
                        date: '2016-05-01',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1519 弄'
                    }, {
                        id: 32,
                        date: '2016-05-01',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1519 弄'
                    }]
                }, {
                    id: 4,
                    date: '2016-05-03',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1516 弄',
                    sort:'4',
                    type:'fa',
                }],
            multipleSelection: []

        }
    },
    components: {
        Pagination
    },
    methods: {
        //列表单选多选
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //进入修改页面
        goChange(id) {
            this.$router.push('/medicine/medClassify/editClass')
        },
        //删除药品
        deleteMed(id) {
            this.$confirm('此操作将删除该种药品分类, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //获取点击的页码-------------------------------
        getPagination(page) {
            //   console.log('----',page);
            // this.currentPage = page;
            // if (this.searchStatus) {//点击了查询按钮---搜索数据---再点击分页
            //     //0-7  8 -15  page=1 2 3 
            //     console.log(page);
            //     this.tableData = this.listTotal.slice((page - 1) * 8, page * 8)
            //     return;
            // }
            //默认产品列表的分页功能

        },
        //父类底色
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex == 1) {

                return 'warning-row';
            }
            return '';
        }
    },


}



</script>

<style lang="less" scoped>
 /deep/ .el-table__row{
background-color: #fafad2;
}
/deep/ .el-table__row--level-1{
background-color: #fff;
}
</style>